import Store from '@/store'
import Cookies from 'js-cookie'
const TokenKey = 'Authorization'

export function routerList(route) {
  if (route.meta.title && route.meta.title.length) {
    let routerList = Store.state.routerList || []
    let index = routerList.findIndex(item => item.path === route.path)
    let { fullPath, path, meta, name, query, params } = route
    if (index <= -1) {
      routerList.push({ fullPath, path, meta, name, query, params })
    } else {
      routerList = routerList.slice(0, index + 1)
    }
    Store.commit('setRouterList', routerList)
  }
}

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setCookie(name, value) {
  return Cookies.set(name, value)
}

export function getCookie(name) {
  return Cookies.get(name)
}

export function removeCookie(name) {
  return Cookies.remove(name)
}
